package com.hotel.front;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.StatusTitle;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.hotel.BL.*;

import data.*;

@SuppressWarnings("serial")
public class WorkaroundService extends HttpServlet {
		//http://localhost:8080/workaroundService?func=EditLang&hotelId=1&lang=en
	
		protected static DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
	
		public void doGet(HttpServletRequest req, HttpServletResponse resp)
				throws IOException {

			String func = req.getParameter("func");
			
			try{
				
				if(func.equals("EditLang"))
					EditLang(req,resp);
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		private void EditLang(HttpServletRequest req, HttpServletResponse resp) {
			String lang = req.getParameter("lang");
			
			long hotelId = Long.parseLong(req.getParameter("hotelId"));
			
			LanguageMaster l;
			General g = new GenericLogic(req,resp).GetGeneral(hotelId);
			
			if(lang.toLowerCase().equals("th"))
				l = new MasterCreator().GetLanguage(StatusTitle.LanguageTitle.Thai);
			else
				l = new MasterCreator().GetLanguage(StatusTitle.LanguageTitle.English);
			
			g.setDefaultLanguage(l);
			
			datastore.put(g.getEntity());
		}
}
